package com.health_predict_springboot.service.impl;

import com.health_predict_springboot.dao.HealthNormalRangeMapper;
import com.health_predict_springboot.pojo.HealthNormalRange;
import com.health_predict_springboot.service.HealthNormalRangeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class HealthNormalRangeServiceImpl implements HealthNormalRangeService {

    @Autowired
    private HealthNormalRangeMapper healthNormalRangeMapper;

    @Override
    public HealthNormalRange getNormalRangeById(Integer rangeId) {
        return healthNormalRangeMapper.selectByRangeId(rangeId);
    }

    @Override
    public List<HealthNormalRange> getNormalRangeByIndicatorName(String indicatorName) {
        HealthNormalRange normalRange = healthNormalRangeMapper.selectByIndicatorName(indicatorName);
        List<HealthNormalRange> resultList = new ArrayList<>();
        if (normalRange != null) {
            resultList.add(normalRange);
        }
        return resultList;
    }

    @Override
    public List<HealthNormalRange> getAllNormalRanges() {
        return healthNormalRangeMapper.selectAllNormalRanges();
    }

    @Override
    public boolean addNormalRange(HealthNormalRange normalRange) {
        return healthNormalRangeMapper.insertNormalRange(normalRange) > 0;
    }

    @Override
    public boolean updateNormalRange(HealthNormalRange normalRange) {
        return healthNormalRangeMapper.updateNormalRange(normalRange) > 0;
    }

    @Override
    public boolean deleteNormalRange(Integer rangeId) {
        return healthNormalRangeMapper.deleteNormalRange(rangeId) > 0;
    }

    @Override
    public List<HealthNormalRange> getNormalRangesByPage(Map<String, Object> params) {
        return healthNormalRangeMapper.selectNormalRangesByPage(params);
    }

    @Override
    public int getNormalRangeCount(Map<String, Object> params) {
        return healthNormalRangeMapper.selectNormalRangeCount(params);
    }
}